<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="物料组编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['groupCode', validatorRules.groupCode]" placeholder="请输入物料组编码"></a-input>
        </a-form-item>
        <a-form-item label="物料组名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['groupName', validatorRules.groupName]" placeholder="请输入物料组名称"></a-input>
        </a-form-item>
        <a-form-item label="物料组类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['groupType', validatorRules.groupType]" :trigger-change="true" dictCode="group_type" placeholder="请选择物料组类型"/>
        </a-form-item>
        <a-form-item label="工艺名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['craftName']" placeholder="请输入工艺名称"></a-input>
        </a-form-item>
        <a-form-item label="加工面" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['processSide']" placeholder="请输入加工面"></a-input>
        </a-form-item>
        <a-form-item label="不良报废标志" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['discardedToken']" :trigger-change="true" dictCode="yn" placeholder="请选择不良报废标志"/>
        </a-form-item>
        <a-form-item label="FQC自动送检" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['fqcAutocheck']" :trigger-change="true" dictCode="yn" placeholder="请选择FQC自动送检"/>
        </a-form-item>
        <a-form-item label="送批数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sendChecknum']" placeholder="请输入送批数量"></a-input>
        </a-form-item>
        <a-form-item label="维修上限次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fixLimit']" placeholder="请输入维修上限次数"></a-input>
        </a-form-item>
        <a-form-item label="管控类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['controlType']" placeholder="请输入管控类型"></a-input>
        </a-form-item>
        <a-form-item label="产品条码规则" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productBarcode']" placeholder="请输入产品条码规则"></a-input>
        </a-form-item>
        <a-form-item label="小板条码规则" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['smallBarcode']" placeholder="请输入小板条码规则"></a-input>
        </a-form-item>
        <a-form-item label="联板数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['linkBoards']" placeholder="请输入联板数"></a-input>
        </a-form-item>
        <a-form-item label="条码拼板数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['barcodeBoards']" placeholder="请输入条码拼板数"></a-input>
        </a-form-item>
        <a-form-item label="库存复检周期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['stockCheckcycle']" placeholder="请输入库存复检周期"></a-input>
        </a-form-item>
        <a-form-item label="复检提醒天数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['checkRemindays']" placeholder="请输入复检提醒天数"></a-input>
        </a-form-item>
        <a-form-item label="老化时长" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['agingHours']" placeholder="请输入老化时长"></a-input>
        </a-form-item>
        <a-form-item label="呆滞周期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tranceCycle']" placeholder="请输入呆滞周期"></a-input>
        </a-form-item>
        <a-form-item label="体积" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bulk']" placeholder="请输入体积"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"


  export default {
    name: "MesChiefdataGoodsgroupModal",
    components: { 
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          groupCode: {
            rules: [
              { required: true, message: '请输入物料组编码!'},
            ]
          },
          groupName: {
            rules: [
              { required: true, message: '请输入物料组名称!'},
            ]
          },
          groupType: {
            rules: [
              { required: true, message: '请输入物料组类型!'},
            ]
          },
        },
        url: {
          add: "/chiefdata/mesChiefdataGoodsgroup/add",
          edit: "/chiefdata/mesChiefdataGoodsgroup/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'groupCode','groupName','groupType','craftName','processSide','discardedToken','fqcAutocheck','sendChecknum','fixLimit','controlType','productBarcode','smallBarcode','linkBoards','barcodeBoards','stockCheckcycle','checkRemindays','agingHours','tranceCycle','bulk'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'groupCode','groupName','groupType','craftName','processSide','discardedToken','fqcAutocheck','sendChecknum','fixLimit','controlType','productBarcode','smallBarcode','linkBoards','barcodeBoards','stockCheckcycle','checkRemindays','agingHours','tranceCycle','bulk'))
      },

      
    }
  }
</script>